//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_mobileMarker.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_side","_side_color","_array","_i","_veh","_marker","_var_name","_var_side","_found_vehs"];

_side = "west";
_side_color = "ColorBlufor";
switch (true) do
{
	case (BTC_side == west) : {_side = "west";_side_color="ColorBlufor";};
	case (BTC_side == east) : {_side = "east";_side_color="ColorOpfor";};
	case (BTC_side == resistance) : {_side = "guer";_side_color="ColorGreen";};
	case (BTC_side == civilian) : {_side = "civ";_side_color="ColorBlack";};
};

_var_side = format["BTC_mobile_%1",_side];
_var_name_side = format["BTC_mobile_name_%1",_side];
_found_vehs = [];
while {(BTC_mobile_respawn == 1)} do {
	_array = missionNamespace getVariable [format["BTC_vehs_mobile_%1_str",_side],[]];
	{
		_veh = _x;
		if (!isnil "_veh" && {!isnull _veh} && {_veh isKindOf "AllVehicles"}) then {
			_var_name = _veh getVariable [_var_side,""];
			if (_var_name in _array) then {
				_display_name = _veh getVariable [_var_name_side,_var_name];
				_found_vehs set [count _found_vehs, _var_name];
				_marker = format["marker_%1",_var_name];
				if (markerType _marker == "") then {
					TRACE_1("Adding Marker",ARR_3(_var_name,_marker,_veh));
					createMarkerLocal [_marker, getPos _veh];
					_marker setMarkerShapeLocal "ICON";
					_marker setMarkerSizeLocal [0.7,0.7];
				};
				_marker setMarkerPosLocal (getPos _veh);
				_marker setMarkerColorLocal _side_color;
				if (speed _veh <= 1 || (count (crew _veh) <= 0)) then {
					_marker setMarkerTypeLocal BTC_Vehicle_MarkerType;
					_marker setMarkerColorLocal _side_color;
					_marker setMarkerTextLocal _display_name;
				} else {
					_marker setMarkerTypeLocal BTC_Vehicle_MarkerTypeMove;
					_marker setMarkerColorLocal "ColorWhite";
					_marker setMarkerTextLocal format["%1: %2 (%3)",_display_name,name (driver _veh), count (crew _veh)];
				};
				if (!alive _veh) then {
					_marker setMarkerTypeLocal BTC_Vehicle_MarkerTypeDestroy;
					_marker setMarkerColorLocal "ColorRed";
					_marker setMarkerTextLocal Format["%1 is Destroyed!",_display_name];
				};
			};
		};
	} foreach vehicles;
	_marker_to_delete = _array - _found_vehs;
	{
		_var_name = _x;
		_marker = format["marker_%1",_var_name];
		deleteMarkerLocal _marker;
	} foreach _marker_to_delete;
	sleep 1.78954;
};
